import React ,{useState}from 'react'
import { Button } from 'antd-mobile'
import { useNavigate } from 'react-router-dom'
function My() {
    const navigate = useNavigate()
  const [name,setName] = useState(localStorage.getItem('username')||'')
    // (2)点击退出按钮实现退出功能,跳转到登录页,清除本地存储的token值

  const goLogin = ()=>{
    localStorage.removeItem('accessToken')
    localStorage.removeItem('refreshToken')
    localStorage.removeItem('username')
    localStorage.removeItem('avator')
    navigate('/login')
  }
  return (
    <div>
        {
          // (1)登陆成功后需要在我的页面展示用户信息，自定义一个退出按钮
            name ? <div>欢迎{name}</div> : <Button onClick={()=>goLogin()}>请先登录</Button>
        }
    </div>
  )
}

export default My
